package com.medvalley.tcm.service.impl;

import com.google.common.collect.Maps;
import com.medvalley.tcm.base.BusinessException;
import com.medvalley.tcm.dao.*;
import com.medvalley.tcm.domain.*;
import com.medvalley.tcm.pojo.*;
import com.medvalley.tcm.service.ReportDetailService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
public class ReportDetailServiceImpl implements ReportDetailService {

    @Autowired
    private TongueDao tongueDao;

    @Autowired
    private SickInfoDao sickInfoDao;

    @Autowired
    private SickUserDao sickUserDao;

    @Autowired
    private PulseDao pulseDao;

    @Autowired
    private PulseDataDao pulseDataDao;

    @Autowired
    private EarDataDao earDataDao;

    @Autowired
    private AnalyzeResultDao analyzeResultDao;

    @Override
    public BodySystemPoint calculateBodySystemPoint(long reportId, String phone) {
        checkUser(phone, reportId);
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("没有此病例数据"));
        long tongueId = sickInfo.getTongueID();
        if (tongueId <= 0) {
            return null;
        }
        BodySystemPoint bodySystemPoint = doCalculateBodySystemPoint(tongueId);
        bodySystemPoint.setGender(sickInfo.getPatientSex());

        return bodySystemPoint;
    }

    @Override
    public BodySystemPoint calculateBodySystemPoint(long reportId) {
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("没有此病例数据"));
        long tongueId = sickInfo.getTongueID();
        if (tongueId <= 0) {
            return null;
        }
        BodySystemPoint bodySystemPoint = doCalculateBodySystemPoint(tongueId);
        bodySystemPoint.setGender(sickInfo.getPatientSex());

        return bodySystemPoint;
    }

    @Override
    public Map<String, Object> resultCollect(long reportId, String phone) {
        checkUser(phone, reportId);
        Map<String, Object> resultMap = Maps.newHashMap();
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("查无此报告"));
        // 舌像和面像
        long tongueId = sickInfo.getTongueID();
        TonguePojo tonguePojo = this.getTonguePojo(tongueId);
        resultMap.put("tongueAndFace", tonguePojo);

        //脉诊
        long pulseId = sickInfo.getPulseID();
        PulsePojo pulsePojo = this.getPulsePojo(pulseId);
        resultMap.put("pulse", pulsePojo);

        // 体质辨识 TODO:需要确认
        resultMap.put("physique", sickInfo.getPhysiqueType());

        // 耳电
        long earId = sickInfo.getEarID();
        EarPojo earPojo = this.getEarPojo(earId);
        resultMap.put("ear", earPojo);

        // 综合建议
        String allAdvice = sickInfo.getDoctorDiagnosis();
        resultMap.put("advice", allAdvice);

        return resultMap;
    }

    @Override
    public TonguePojo getFaceAndTongue(long reportId, String phone) {
        checkUser(phone, reportId);
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("查无此报告"));
        TonguePojo tonguePojo = this.getTonguePojo(sickInfo.getTongueID());
        // 计算望诊趋势得分
        this.calculateTotalPoint(tonguePojo);
        return tonguePojo;
    }

    @Override
    public TonguePojo getFaceAndTongue(long reportId) {
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("查无此报告"));
        TonguePojo tonguePojo = this.getTonguePojo(sickInfo.getTongueID());
        // 计算望诊趋势得分
        this.calculateTotalPoint(tonguePojo);
        return tonguePojo;
    }

    private TonguePojo getTonguePojo(long tongueId) {
        Tongue tongue = tongueDao.findById(tongueId).orElse(new Tongue());
        TonguePojo tonguePojo = new TonguePojo();
        BeanUtils.copyProperties(tongue, tonguePojo);
        return tonguePojo;
    }

    @Override
    public PulsePojo getPulseData(long reportId, String phone) {
        checkUser(phone, reportId);
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("查无此报告"));
        return this.getPulsePojo(sickInfo.getPulseID());
    }

    private PulsePojo getPulsePojo(long pulseId) {
        PulsePojo pulsePojo = new PulsePojo();
        Pulse pulse = pulseDao.findById(pulseId).orElse(new Pulse());
        List<PulseData> pulseDatas = pulseDataDao.findAllByPulseId(pulseId);
        BeanUtils.copyProperties(pulse, pulsePojo);
        List<PulseDataPojo> pulseDataPojoList = pulseDatas.stream().map((e) -> {
            PulseDataPojo pulseDataPojo = new PulseDataPojo();
            BeanUtils.copyProperties(e, pulseDataPojo);
            return pulseDataPojo;
        }).collect(Collectors.toList());
        pulsePojo.setPulseDatas(pulseDataPojoList);
        return pulsePojo;
    }

    @Override
    public BigDataAnalyze getBigDataAnalyze(long reportId, String phone) {
        checkUser(phone, reportId);
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("查无此报告"));
        String userName = sickInfo.getPatientName();
        String physique = sickInfo.getPhysiqueType();
        BigDataAnalyze bigDataAnalyze = new BigDataAnalyze();
        bigDataAnalyze.setTitle(String.format(bigDataAnalyze.getTitle(), userName));
        bigDataAnalyze.setHabitus(physique);
        return bigDataAnalyze;
    }

    @Override
    public EarPojo getEarData(long reportId, String phone) {
        checkUser(phone, reportId);
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("查无此报告"));
        return this.getEarPojo(sickInfo.getEarID());
    }

    @Override
    public String getPhysique(long reportId, String phone) {
        checkUser(phone, reportId);
        SickInfo sickInfo = sickInfoDao.findById(reportId).orElseThrow(() -> new BusinessException("查无此报告"));
        return sickInfo.getPhysiqueType();
    }

    @Override
    public String analyzeResult(String name) {
        AnalyzeResult analyzeResult = analyzeResultDao.findOneByName(name);
        return analyzeResult.getDescription();
    }

    private EarPojo getEarPojo(long earId) {
        EarData earData = earDataDao.findById(earId).orElse(new EarData());
        EarPojo earPojo = new EarPojo();
        BeanUtils.copyProperties(earData, earPojo);
        return earPojo;
    }


    private BodySystemPoint doCalculateBodySystemPoint(long tongueId) {
        BodySystemPoint bodySystemPoint = new BodySystemPoint();
        Tongue _t = tongueDao.findById(tongueId).get();
        int[] _list = new int[]{bodySystemPoint.getYundongSystem(), bodySystemPoint.getShengzhiSystem(),
                bodySystemPoint.getNeifenmiSystem(), bodySystemPoint.getXunhuanSystem(), bodySystemPoint.getHuxiSystem(),
                bodySystemPoint.getXiaohuaSystem(), bodySystemPoint.getMiniaoSystem(), bodySystemPoint.getShengzhiSystem(), bodySystemPoint.getMianyiSystem()};
        //舌神判断
        String tongueSpirit = Optional.ofNullable(_t.getTongueSpirit()).orElse("");
        if (tongueSpirit.contains("枯")) {
            int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        //舌态判断
        String tongueState = Optional.ofNullable(_t.getTongueState()).orElse("");
        if (tongueState.contains("萎软") || tongueState.contains("痿软")) {
            int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueState.contains("强硬而红降少津")) {
            boolean _isContains = false;
            if (tongueState.contains("强硬而红降少津")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("强硬而舌苔厚腻")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("突然舌强硬而语言")) {
                int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueState.contains("歪斜")) {
            int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        if (tongueState.contains("颤动")) {
            boolean _isContains = false;
            if (tongueState.contains("舌淡白而颤动")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("舌绛紫而颤动")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("舌红少苔而颤动")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("酒毒内蕴")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueState.contains("吐弄") || tongueState.contains("可见小儿智力发育不全")) {
            int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        if (tongueState.contains("短缩")) {
            boolean _isContains = false;
            if (tongueState.contains("舌短缩伴舌青紫而湿润")) {
                int[] _arr = new int[]{
                        1, 3, 2, 3, 3, 1, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("舌短缩伴舌淡白")) {
                int[] _arr = new int[]{
                        1, 1, 1, 2, 1, 1, 0, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("舌短缩伴色降红而干")) {
                int[] _arr = new int[]{
                        1, 2, 1, 2, 1, 2, 1, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("舌短缩伴胖大")) {
                int[] _arr = new int[]{
                        0, 0, 1, 2, 1, 2, 1, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueState.contains("绊舌")) {
                int[] _arr = new int[]{
                        3, 3, 2, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3};
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        //舌质颜色
        String tongueColorType = Optional.ofNullable(_t.getTongueColorType()).orElse("");

        if (tongueColorType.contains("淡白")) {
            boolean _isContains = false;
            if (tongueColorType.contains("舌色淡，舌体瘦薄")) {
                int[] _arr = new int[]{
                        1, 0, 0, 3, 0, 2, 0, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("淡白湿润，舌体胖嫩")) {
                int[] _arr = new int[]{
                        1, 0, 0, 3, 0, 2, 0, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("枯白舌")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 0, 2, 0, 2, 0, 2, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueColorType.contains("红舌")) {
            boolean _isContains = false;
            if (tongueColorType.contains("舌色稍红")) {
                int[] _arr = new int[]{
                        1, 0, 1, 1, 1, 1, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("仅舌边尖略红")) {
                int[] _arr = new int[]{
                        1, 0, 1, 1, 1, 0, 1, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("舌尖红")) {
                int[] _arr = new int[]{0, 1, 1, 2, 1, 0, 1, 0, 1};
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("舌两边红")) {
                int[] _arr = new int[]{
                        0, 0, 2, 3, 0, 1, 0, 1, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("红而有苔")) {
                int[] _arr = new int[]{
                        0, 0, 1, 1, 1, 1, 1, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("鲜红而少苔或有裂纹")) {
                int[] _arr = new int[]{
                        1, 1, 2, 3, 2, 2, 2, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 1, 1, 1, 1, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueColorType.contains("绛舌")) {
            boolean _isContains = false;
            if (tongueColorType.contains("红绛而有苔")) {
                int[] _arr = new int[]{
                        1, 1, 2, 2, 1, 1, 2, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("红绛而少苔或无苔")) {
                int[] _arr = new int[]{
                        1, 1, 3, 3, 2, 3, 3, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 1, 3, 3, 3, 2, 2, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueColorType.contains("青紫舌")) {
            boolean _isContains = false;
            if (tongueColorType.contains("淡紫舌")) {
                int[] _arr = new int[]{
                        1, 0, 1, 1, 1, 1, 0, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("绛紫舌")) {
                int[] _arr = new int[]{
                        2, 0, 2, 2, 2, 2, 1, 0, 2};
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("绛紫色深，干枯少津")) {
                int[] _arr = new int[]{
                        2, 1, 2, 2, 2, 3, 1, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("淡紫或青紫湿润")) {
                int[] _arr = new int[]{1, 0, 1, 1, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("全舌见紫色")) {
                int[] _arr = new int[]{2, 1, 2, 2, 2, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueColorType.contains("瘀斑舌")) {
                int[] _arr = new int[]{
                        2, 1, 2, 3, 2, 2, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 2, 1, 0, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        String tongueCoatColorType = Optional.ofNullable(_t.getTongueCoatColorType()).orElse("");

        // 舌苔颜色
        if (tongueCoatColorType.contains("白苔")) {
            boolean _isContains = false;
            if (tongueCoatColorType.contains("积粉苔")) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 1, 3, 2, 0, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("苔白而燥裂")) {
                int[] _arr = new int[]{
                        1, 0, 2, 2, 1, 2, 2, 0, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("薄白而淡")) {
                int[] _arr = new int[]{
                        0, 0, 0, 1, 0, 1, 0, 0, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("薄白而润")) {
                int[] _arr = new int[]{
                        0, 0, 0, 0, 0, 0, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("薄白而干")) {
                int[] _arr = new int[]{
                        0, 0, 0, 0, 1, 0, 0, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("薄白而滑")) {
                int[] _arr = new int[]{
                        1, 0, 0, 1, 0, 2, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("白厚腻")) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 0, 3, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("白厚而干")) {
                int[] _arr = new int[]{
                        1, 0, 2, 2, 2, 3, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 1, 1, 1, 0, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueCoatColorType.contains("黄苔")) {
            boolean _isContains = false;
            if (tongueCoatColorType.contains("淡黄苔")) {
                int[] _arr = new int[]{
                        0, 0, 1, 1, 0, 1, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("深黄苔")) {
                int[] _arr = new int[]{
                        1, 0, 0, 1, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("焦黄苔")) {
                int[] _arr = new int[]{
                        2, 0, 2, 3, 2, 2, 2, 0, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("黄膩苔")) {
                int[] _arr = new int[]{
                        2, 0, 2, 3, 0, 3, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("黄黏膩苔")) {
                int[] _arr = new int[]{
                        2, 0, 2, 3, 1, 3, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("黄糙苔")) {
                int[] _arr = new int[]{
                        2, 0, 2, 3, 2, 2, 3, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("黄瓣苔")) {
                int[] _arr = new int[]{
                        1, 1, 2, 2, 2, 3, 2, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("黄滑苔")) {
                int[] _arr = new int[]{
                        0, 0, 1, 1, 1, 2, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 1, 1, 1, 1, 1, 1, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }


        if (tongueCoatColorType.contains("灰黑苔")) {
            boolean _isContains = false;
            if (tongueCoatColorType.contains("灰黑色浅而润")) {
                int[] _arr = new int[]{
                        2, 1, 1, 2, 1, 1, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("灰黑色深而干燥无津")) {
                int[] _arr = new int[]{
                        2, 0, 2, 2, 2, 2, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("白腻灰黑苔")) {
                int[] _arr = new int[]{
                        2, 0, 1, 2, 1, 2, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("黄腻灰黑苔")) {
                int[] _arr = new int[]{
                        2, 1, 1, 2, 1, 2, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("苔焦黑干燥，舌质干裂起刺")) {
                int[] _arr = new int[]{
                        3, 2, 2, 3, 2, 3, 3, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatColorType.contains("霉酱苔")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 2, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        2, 2, 2, 3, 2, 3, 3, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        //苔质
        String tongueCoatType = Optional.ofNullable(_t.getTongueCoatType()).orElse("");

        if (tongueCoatType.contains("薄苔")) {
            int[] _arr = new int[]{
                    0, 0, 0, 0, 0, 1, 0, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("厚苔")) {
            int[] _arr = new int[]{
                    1, 0, 0, 1, 1, 2, 0, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("润苔")) {
            int[] _arr = new int[]{
                    0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("滑苔")) {
            int[] _arr = new int[]{
                    0, 0, 1, 2, 1, 1, 1, 0, 0
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("燥苔")) {
            int[] _arr = new int[]{
                    1, 1, 1, 2, 2, 2, 2, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("糙苔")) {
            int[] _arr = new int[]{
                    1, 1, 1, 2, 2, 2, 2, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("类剥苔")) {
            int[] _arr = new int[]{
                    2, 1, 2, 2, 2, 2, 2, 2, 2
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        if (tongueCoatType.contains("全苔")) {
            int[] _arr = new int[]{
                    1, 0, 1, 2, 1, 2, 1, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("真苔")) {
            int[] _arr = new int[]{
                    0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueCoatType.contains("假苔")) {
            int[] _arr = new int[]{
                    0, 0, 1, 2, 0, 2, 0, 0, 0
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }


        if (tongueCoatType.contains("膩苔")) {
            boolean _isContains = false;
            if (tongueCoatType.contains("垢腻苔")) {
                int[] _arr = new int[]{
                        1, 0, 2, 2, 1, 3, 1, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("黏腻苔")) {
                int[] _arr = new int[]{
                        1, 1, 2, 2, 1, 3, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("滑腻苔")) {
                int[] _arr = new int[]{
                        1, 0, 2, 2, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("燥膩苔")) {
                int[] _arr = new int[]{
                        2, 1, 2, 2, 2, 2, 2, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }


            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueCoatType.contains("腐苔")) {
            boolean _isContains = false;
            if (tongueCoatType.contains("脓腐苔")) {
                int[] _arr = new int[]{
                        2, 2, 3, 3, 2, 3, 3, 2, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("霉腐苔")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        0, 0, 0, 0, 0, 3, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }


        if (tongueCoatType.contains("剥苔")) {
            boolean _isContains = false;
            if (tongueCoatType.contains("前剥苔")) {
                int[] _arr = new int[]{
                        2, 1, 1, 3, 3, 2, 2, 1, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("中剥苔")) {
                int[] _arr = new int[]{
                        2, 1, 2, 2, 2, 3, 1, 1, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("根剥苔")) {
                int[] _arr = new int[]{
                        2, 1, 2, 2, 2, 2, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("花剥苔")) {
                int[] _arr = new int[]{
                        2, 2, 3, 3, 3, 3, 2, 2, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("鸡心苔")) {
                int[] _arr = new int[]{
                        2, 2, 3, 3, 3, 3, 3, 3, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("地图苔")) {
                int[] _arr = new int[]{
                        3, 2, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("舌红而剥苔")) {
                int[] _arr = new int[]{
                        2, 3, 2, 3, 3, 3, 3, 3, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("舌淡白而剥苔")) {
                int[] _arr = new int[]{
                        2, 1, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("先天性剥苔")) {
                int[] _arr = new int[]{
                        1, 1, 2, 2, 2, 2, 2, 2, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        2, 1, 2, 3, 2, 2, 2, 2, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueCoatType.contains("镜面舌")) {
            boolean _isContains = false;
            if (tongueCoatType.contains("舌红而镜面舌")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("舌色白而镜面舌")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueCoatType.contains("偏苔")) {
            boolean _isContains = false;
            if (tongueCoatType.contains("偏外苔")) {
                int[] _arr = new int[]{
                        1, 0, 2, 2, 2, 3, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("偏内苔")) {
                int[] _arr = new int[]{
                        0, 0, 1, 1, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("仅见中根部有苔")) {
                int[] _arr = new int[]{
                        0, 0, 0, 1, 1, 1, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("偏于左右一侧")) {
                int[] _arr = new int[]{
                        0, 0, 3, 3, 0, 2, 0, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueCoatType.contains("咀嚼习惯使偏苔或牙齿脱落使偏苔")) {
                int[] _arr = new int[]{
                        1, 0, 0, 0, 0, 1, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }


            if (!_isContains) {
                int[] _arr = new int[]{
                        0, 0, 0, 0, 0, 0, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        //舌型
        String tongueShape = Optional.ofNullable(_t.getTongueShape()).orElse("");
        if (tongueShape.contains("老舌")) {
            int[] _arr = new int[]{
                    1, 1, 1, 1, 1, 1, 0, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        if (tongueShape.contains("嫩舌")) {
            boolean _isContains = false;
            if (tongueShape.contains("舌嫩色淡白")) {
                int[] _arr = new int[]{
                        0, 0, 1, 3, 1, 2, 1, 0, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("舌嫩红少苔")) {
                int[] _arr = new int[]{
                        2, 0, 1, 2, 2, 3, 2, 0, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 2, 2, 1, 2, 2, 0, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }

        if (tongueShape.contains("胖大舌")) {
            boolean _isContains = false;
            if (tongueShape.contains("舌色淡白，舌体胖嫩")) {
                int[] _arr = new int[]{
                        3, 0, 3, 0, 0, 2, 2, 2, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("先天性舌血管瘤者可见舌局部肿胀色紫")) {
                int[] _arr = new int[]{
                        0, 0, 0, 0, 0, 0, 0, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 2, 2, 1, 2, 2, 0, 3
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }
        if (tongueShape.contains("肿胀舌")) {
            boolean _isContains = false;
            if (tongueShape.contains("舌胀大而色红")) {
                int[] _arr = new int[]{
                        2, 2, 3, 3, 2, 3, 3, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("舌肿胀色红绛")) {
                int[] _arr = new int[]{
                        2, 3, 3, 3, 3, 3, 3, 2, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        2, 2, 3, 3, 2, 3, 3, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }
        if (tongueShape.contains("瘦薄舌")) {
            boolean _isContains = false;
            if (tongueShape.contains("舌体瘦薄，舌色淡白")) {
                int[] _arr = new int[]{
                        2, 1, 2, 2, 2, 3, 2, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("舌体瘦薄，舌色红绛")) {
                int[] _arr = new int[]{
                        2, 3, 3, 2, 2, 2, 3, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        2, 2, 3, 2, 2, 2, 2, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }
        if (tongueShape.contains("点刺舌")) {
            boolean _isContains = false;
            if (tongueShape.contains("舌尖点刺舌")) {
                int[] _arr = new int[]{
                        2, 2, 2, 3, 3, 2, 2, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("舌中点刺舌")) {
                int[] _arr = new int[]{
                        2, 2, 2, 3, 3, 3, 3, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("舌两边点刺舌")) {
                int[] _arr = new int[]{
                        3, 2, 3, 3, 2, 2, 2, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("点刺鲜红")) {
                int[] _arr = new int[]{
                        2, 1, 2, 2, 1, 2, 2, 3, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("点刺绛紫")) {
                int[] _arr = new int[]{
                        3, 3, 3, 3, 3, 3, 3, 3, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (!_isContains) {
                int[] _arr = new int[]{
                        2, 2, 2, 2, 2, 2, 2, 1, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }
        if (tongueShape.contains("裂纹舌")) {
            boolean _isContains = false;
            if (tongueShape.contains("淡白而裂")) {
                int[] _arr = new int[]{
                        2, 1, 2, 2, 1, 2, 1, 0, 2
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("红绛而裂")) {
                int[] _arr = new int[]{
                        2, 3, 3, 3, 1, 2, 2, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("有横真裂纹而短小者")) {
                int[] _arr = new int[]{
                        2, 1, 1, 2, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("色淡白而胖嫩，边有齿痕又兼见裂纹")) {
                int[] _arr = new int[]{
                        2, 1, 1, 1, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("先天性裂纹")) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 0, 1, 0, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        2, 3, 2, 2, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }
        if (tongueShape.contains("齿痕舌")) {
            boolean _isContains = false;
            if (tongueShape.contains("舌体胖大润而齿痕")) {
                int[] _arr = new int[]{
                        1, 1, 1, 2, 1, 2, 1, 0, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("舌色淡红而齿痕")) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 0, 2, 2, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("舌红肿胀满口而齿痕")) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 1, 2, 1, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }
            if (tongueShape.contains("先天性齿痕，多见舌体不大，舌淡红而嫩")) {
                int[] _arr = new int[]{
                        0, 0, 0, 2, 1, 1, 1, 1, 1
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
                _isContains = true;
            }

            if (!_isContains) {
                int[] _arr = new int[]{
                        1, 0, 1, 2, 1, 2, 1, 0, 0
                };
                for (int i = 0; i < _list.length; i++) {
                    _list[i] -= _arr[i];
                }
            }
        }
        //舌下
        String tongueMailuo = Optional.ofNullable(_t.getTongueMailuo()).orElse("");
        if (tongueMailuo.contains("络脉细")) {
            int[] _arr = new int[]{
                    1, 0, 1, 2, 1, 1, 1, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (tongueMailuo.contains("络脉粗")) {
            int[] _arr = new int[]{
                    2, 2, 1, 3, 1, 2, 1, 0, 0
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        //面色
        String faceColor = Optional.ofNullable(_t.getFaceColor()).orElse("");
        if (faceColor.contains("满面白色")) {
            int[] _arr = new int[]{
                    1, 0, 1, 1, 2, 1, 1, 0, 2
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (faceColor.contains("满面黄色")) {
            int[] _arr = new int[]{
                    1, 1, 2, 2, 1, 2, 1, 0, 0
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (faceColor.contains("满面赤色")) {
            int[] _arr = new int[]{
                    1, 1, 1, 2, 1, 1, 1, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (faceColor.contains("满面青色")) {
            int[] _arr = new int[]{
                    1, 2, 3, 3, 1, 1, 1, 1, 0
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (faceColor.contains("满面黑色")) {
            int[] _arr = new int[]{
                    2, 1, 1, 1, 1, 1, 2, 2, 2
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        //人中形态
        String renZhongXingTai = Optional.ofNullable(_t.getRenZhongXingTai()).orElse("");
        if (!renZhongXingTai.contains("正常")) {
            int[] _arr = new int[]{
                    3, 3, 3, 3, 3, 3, 3, 3, 3
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        //人中颜色
        String renZhongColor = Optional.ofNullable(_t.getRenZhongColor()).orElse("");
        if (!renZhongColor.contains("正常")) {
            int[] _arr = new int[]{
                    3, 3, 3, 3, 3, 3, 3, 3, 3
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        //唇色
        String lipColorType = Optional.ofNullable(_t.getLipColorType()).orElse("");
        if (lipColorType.contains("灰白")) {
            int[] _arr = new int[]{
                    2, 1, 2, 2, 2, 2, 1, 0, 2
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }
        if (lipColorType.contains("青紫")) {
            int[] _arr = new int[]{
                    3, 1, 3, 3, 1, 1, 1, 0, 1
            };
            for (int i = 0; i < _list.length; i++) {
                _list[i] -= _arr[i];
            }
        }

        int sumBody = 0;
        for (int i = 0; i < _list.length; i++) {
            _list[i] = this.finalPoint(_list[i]);
            sumBody += _list[i];
        }
        bodySystemPoint.setYundongSystem(_list[0]);
        bodySystemPoint.setShenjingSystem(_list[1]);
        bodySystemPoint.setNeifenmiSystem(_list[2]);
        bodySystemPoint.setXunhuanSystem(_list[3]);
        bodySystemPoint.setHuxiSystem(_list[4]);
        bodySystemPoint.setXiaohuaSystem(_list[5]);
        bodySystemPoint.setMiniaoSystem(_list[6]);
        bodySystemPoint.setShengzhiSystem(_list[7]);
        bodySystemPoint.setMianyiSystem(_list[8]);

        bodySystemPoint.setPointBody(sumBody / _list.length);


        return bodySystemPoint;
    }

    private int finalPoint(int point) {
        point = 100 - (100 - point) * 3;
        return point;
    }

    private void checkUser(String phone, long reportId) {
        SickAndUser sickAndUser = sickUserDao.findOneBySickIdAndPhone(reportId, phone);
        if (sickAndUser == null) {
            throw new BusinessException("此报告不属于您");
        }

    }

    private void calculateTotalPoint(TonguePojo tonguePojo) {
        BodySystemPoint bodySystemPoint = new BodySystemPoint();
        double[] _pointF = bodySystemPoint.getPointF();
        // 舌神
        String tongueSpirit = Optional.ofNullable(tonguePojo.getTongueSpirit()).orElse("");
        //舌态判断
        String tongueState = Optional.ofNullable(tonguePojo.getTongueState()).orElse("");
        //舌下
        String tongueMailuo = Optional.ofNullable(tonguePojo.getTongueMailuo()).orElse("");
        //舌质颜色
        String tongueColorType = Optional.ofNullable(tonguePojo.getTongueColorType()).orElse("");
        //舌型
        String tongueShape = Optional.ofNullable(tonguePojo.getTongueShape()).orElse("");
        String tongueCoatColorType = Optional.ofNullable(tonguePojo.getTongueCoatColorType()).orElse("");
        //苔质
        String tongueCoatType = Optional.ofNullable(tonguePojo.getTongueCoatType()).orElse("");
        //面色
        String faceColor = Optional.ofNullable(tonguePojo.getFaceColor()).orElse("");
        //唇色
        String lipColorType = Optional.ofNullable(tonguePojo.getLipColorType()).orElse("");
        //人中形态
        String renZhongXingTai = Optional.ofNullable(tonguePojo.getRenZhongXingTai()).orElse("");
        //人中颜色
        String renZhongColor = Optional.ofNullable(tonguePojo.getRenZhongColor()).orElse("");

        if (tongueSpirit.contains("荣")) _pointF[0] = RandomUtils.nextDouble(56, 65);
        else _pointF[0] = RandomUtils.nextDouble(96, 100);

        if (tongueState.contains("痿软")) _pointF[1] = RandomUtils.nextDouble(56, 65);
        else if (tongueState.contains("强硬")) _pointF[1] = RandomUtils.nextDouble(56, 65);
        else if (tongueState.contains("歪斜")) _pointF[1] = RandomUtils.nextDouble(56, 65);
        else if (tongueState.contains("颤动")) _pointF[1] = RandomUtils.nextDouble(56, 65);
        else if (tongueState.contains("吐弄")) _pointF[1] = RandomUtils.nextDouble(56, 65);
        else if (tongueState.contains("短缩")) _pointF[1] = RandomUtils.nextDouble(46, 55);
        else _pointF[1] = RandomUtils.nextDouble(96, 100);

        if (tongueMailuo.contains("正常")) _pointF[2] = RandomUtils.nextDouble(96, 100);
        else _pointF[2] = RandomUtils.nextDouble(60, 70);

        if (tongueColorType.contains("淡红")) _pointF[3] = RandomUtils.nextDouble(96, 100);
        else if (tongueColorType.contains("红") || tongueColorType.contains("淡白"))
            _pointF[3] = RandomUtils.nextDouble(76, 95);
        else if (tongueColorType.contains("绛")) _pointF[3] = RandomUtils.nextDouble(56, 75);
        else if (tongueColorType.contains("青紫")) _pointF[3] = RandomUtils.nextDouble(36, 55);


        _pointF[4] = RandomUtils.nextDouble(96, 100);
        if (tongueShape.contains("胖")) _pointF[4] -= 10;
        if (tongueShape.contains("瘦")) _pointF[4] -= 10;
        if (tongueShape.contains("老")) _pointF[4] -= 10;
        else if (tongueShape.contains("嫩")) _pointF[4] -= 10;
        if (tongueShape.contains("点刺")) _pointF[4] -= 10;
        if (tongueShape.contains("裂纹")) _pointF[4] -= 10;
        if (tongueShape.contains("瘀斑")) _pointF[4] -= 10;

        if (tongueCoatColorType.contains("白")) _pointF[5] = RandomUtils.nextDouble(96, 100);
        else if (tongueCoatColorType.contains("淡黄")) _pointF[5] = RandomUtils.nextDouble(86, 95);
        else if (tongueCoatColorType.contains("深黄")) _pointF[5] = RandomUtils.nextDouble(76, 85);
        else if (tongueCoatColorType.contains("焦黄")) _pointF[5] = RandomUtils.nextDouble(56, 75);
        else if (tongueCoatColorType.contains("灰黑")) _pointF[5] = RandomUtils.nextDouble(36, 55);


        if (tongueCoatType.contains("薄")) _pointF[6] = RandomUtils.nextDouble(96, 100);
        else if (tongueCoatType.contains("厚")) _pointF[6] = RandomUtils.nextDouble(86, 95);
        if (tongueCoatType.contains("润")) _pointF[6] = RandomUtils.nextDouble(86, 95);
        else if (tongueCoatType.contains("滑")) _pointF[6] = RandomUtils.nextDouble(76, 85);
        else if (tongueCoatType.contains("燥")) _pointF[6] = RandomUtils.nextDouble(86, 95);
        else if (tongueCoatType.contains("糙")) _pointF[6] = RandomUtils.nextDouble(76, 75);


        if (tongueCoatType.contains("垢腻")) _pointF[6] = RandomUtils.nextDouble(66, 75);
        else if (tongueCoatType.contains("黏腻")) _pointF[6] = RandomUtils.nextDouble(66, 75);
        else if (tongueCoatType.contains("滑腻")) _pointF[6] = RandomUtils.nextDouble(66, 75);
        else if (tongueCoatType.contains("燥腻")) _pointF[6] = RandomUtils.nextDouble(66, 75);
        else if (tongueCoatType.contains("腻")) _pointF[6] = RandomUtils.nextDouble(76, 85);


        if (tongueCoatType.contains("脓腐")) _pointF[6] = RandomUtils.nextDouble(56, 65);
        else if (tongueCoatType.contains("霉腐")) _pointF[6] = RandomUtils.nextDouble(56, 65);
        else if (tongueCoatType.contains("腐")) _pointF[6] = RandomUtils.nextDouble(66, 75);


        if (tongueCoatType.contains("剥") || tongueCoatType.contains("偏")) _pointF[6] = RandomUtils.nextDouble(66, 75);
        if (tongueCoatType.contains("镜面")) _pointF[6] = RandomUtils.nextDouble(56, 65);


        if (faceColor.contains("红黄隐隐")) _pointF[7] = RandomUtils.nextDouble(96, 100);
        else if (faceColor.contains("赤") || faceColor.contains("白") || faceColor.contains("黄"))
            _pointF[7] = RandomUtils.nextDouble(76, 95);
        else if (faceColor.contains("青")) _pointF[7] = RandomUtils.nextDouble(56, 75);
        else if (faceColor.contains("黑")) _pointF[7] = RandomUtils.nextDouble(36, 55);

        if (lipColorType.contains("红润")) _pointF[8] = RandomUtils.nextDouble(96, 100);
        else if (lipColorType.contains("白") || lipColorType.contains("深红"))
            _pointF[8] = RandomUtils.nextDouble(76, 95);
        else if (lipColorType.contains("青") || lipColorType.contains("黑")) _pointF[8] = RandomUtils.nextDouble(76, 95);

        if (renZhongXingTai.contains("正常")) _pointF[9] = RandomUtils.nextDouble(96, 100);
        else _pointF[9] = RandomUtils.nextDouble(56, 75);

        if (renZhongColor.contains("正常")) _pointF[10] = RandomUtils.nextDouble(96, 100);
        else _pointF[10] = _pointF[10] = RandomUtils.nextDouble(56, 75);

        double pointTotal = bodySystemPoint.getPointTotal();
        double[] _pointScale = bodySystemPoint.getPointScale();

        for (int i = 0; i < _pointF.length; i++) {
            pointTotal += _pointF[i] * _pointScale[i];
        }
        pointTotal /= 100.0;

        bodySystemPoint.setPointTotal(pointTotal);
        bodySystemPoint.setPointScale(_pointScale);

        double pointTongue = bodySystemPoint.getPointTongue();
        for (int i = 0; i < 7; i++) {
            pointTongue += _pointF[i] * _pointScale[i];
        }
        pointTongue /= 100.0;
        pointTongue /= 0.8;
        bodySystemPoint.setPointTongue(pointTongue);

        double pointFace = bodySystemPoint.getPointFace();
        for (int i = 7; i < _pointF.length; i++) {
            pointFace += _pointF[i] * _pointScale[i];
        }
        pointFace /= 100.0;
        pointFace /= 0.2;
        bodySystemPoint.setPointFace(pointFace);

        tonguePojo.setPointTotal(pointTotal);
    }
}
